package com.hongkuncheng.cms.model;

import javax.persistence.*;
import java.util.List;
import java.util.Objects;
import java.io.Serializable;

@Entity
public class Admin implements Serializable {
    protected int id;
    protected String account;
    protected String password;
    protected String name;
    protected String sex;
    protected String face;
    protected String position;
    protected String mobile;
    protected String email;
    protected String weixinId;
    protected String description;
    protected int sort;
    protected Department department;
    protected AdminGlobalpermission adminGlobalpermission;
    protected List<AdminReAdminRole> adminReAdminRoles;
    protected List<Article> articles;
    protected List<ChecknodeReAdmin> checknodeReAdmins;
    protected List<Checkrecord> checkrecords;
    protected List<Notice> notices;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", nullable = false)
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    @Basic
    @Column(name = "account", nullable = false, length = 255)
    public String getAccount() {
        return account;
    }

    public void setAccount(String account) {
        this.account = account;
    }

    @Basic
    @Column(name = "password", nullable = false, length = 255)
    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @Basic
    @Column(name = "name", nullable = false, length = 255)
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Basic
    @Column(name = "sex", nullable = true, length = 255)
    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex == null || sex.isEmpty() ? null : sex;
    }

    @Basic
    @Column(name = "face", nullable = true, length = 255)
    public String getFace() {
        return face;
    }

    public void setFace(String face) {
        this.face = face == null || face.isEmpty() ? null : face;
    }

    @Basic
    @Column(name = "position", nullable = true, length = 255)
    public String getPosition() {
        return position;
    }

    public void setPosition(String position) {
        this.position = position == null || position.isEmpty() ? null : position;
    }

    @Basic
    @Column(name = "mobile", nullable = true, length = 255)
    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile == null || mobile.isEmpty() ? null : mobile;
    }

    @Basic
    @Column(name = "email", nullable = true, length = 255)
    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email == null || email.isEmpty() ? null : email;
    }

    @Basic
    @Column(name = "weixin_id", nullable = true, length = 255)
    public String getWeixinId() {
        return weixinId;
    }

    public void setWeixinId(String weixinId) {
        this.weixinId = weixinId == null || weixinId.isEmpty() ? null : weixinId;
    }

    @Basic
    @Column(name = "description", nullable = true, length = -1)
    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description == null || description.isEmpty() ? null : description;
    }

    @Basic
    @Column(name = "sort", nullable = false)
    public int getSort() {
        return sort;
    }

    public void setSort(int sort) {
        this.sort = sort;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Admin admin = (Admin) o;
        return id == admin.id &&
                sort == admin.sort &&
                Objects.equals(account, admin.account) &&
                Objects.equals(password, admin.password) &&
                Objects.equals(name, admin.name) &&
                Objects.equals(sex, admin.sex) &&
                Objects.equals(face, admin.face) &&
                Objects.equals(position, admin.position) &&
                Objects.equals(mobile, admin.mobile) &&
                Objects.equals(email, admin.email) &&
                Objects.equals(weixinId, admin.weixinId) &&
                Objects.equals(description, admin.description);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, account, password, name, sex, face, position, mobile, email, weixinId, description, sort);
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "department_id", referencedColumnName = "id", nullable = false)
    public Department getDepartment() {
        return department;
    }

    public void setDepartment(Department department) {
        this.department = department;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "globalpermission_id", referencedColumnName = "id", nullable = false)
    public AdminGlobalpermission getAdminGlobalpermission() {
        return adminGlobalpermission;
    }

    public void setAdminGlobalpermission(AdminGlobalpermission adminGlobalpermission) {
        this.adminGlobalpermission = adminGlobalpermission;
    }

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "admin")
    public List<AdminReAdminRole> getAdminReAdminRoles() {
        return adminReAdminRoles;
    }

    public void setAdminReAdminRoles(List<AdminReAdminRole> adminReAdminRoles) {
        this.adminReAdminRoles = adminReAdminRoles;
    }

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "admin")
    public List<Article> getArticles() {
        return articles;
    }

    public void setArticles(List<Article> articles) {
        this.articles = articles;
    }

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "admin")
    public List<ChecknodeReAdmin> getChecknodeReAdmins() {
        return checknodeReAdmins;
    }

    public void setChecknodeReAdmins(List<ChecknodeReAdmin> checknodeReAdmins) {
        this.checknodeReAdmins = checknodeReAdmins;
    }

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "admin")
    public List<Checkrecord> getCheckrecords() {
        return checkrecords;
    }

    public void setCheckrecords(List<Checkrecord> checkrecords) {
        this.checkrecords = checkrecords;
    }

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "admin")
    public List<Notice> getNotices() {
        return notices;
    }

    public void setNotices(List<Notice> notices) {
        this.notices = notices;
    }
}
